package com.xuecheng.content.convert;

import com.xuecheng.api.content.model.dto.TeachplanDTO;
import com.xuecheng.api.content.model.dto.TeachplanMediaDTO;
import com.xuecheng.api.content.model.vo.TeachplanVO;
import com.xuecheng.content.entity.Teachplan;
import com.xuecheng.content.entity.TeachplanMedia;
import com.xuecheng.content.entity.ex.TeachplanNode;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import java.util.List;

@Mapper
public interface TeachplanConvert {

    TeachplanConvert INSTANCE = Mappers.getMapper(TeachplanConvert.class);

    /**
     * @param node 源对象
     * @return 转换后的对象
     * @Mapping 映射的是不能转换的属性
     */
    @Mappings({
            @Mapping(source = "id", target = "teachPlanId"),
            @Mapping(source = "childrenNodes", target = "teachPlanTreeNodes")
    })
    TeachplanDTO node2dto(TeachplanNode node);

    List<TeachplanDTO> nodes2dtos(List<TeachplanNode> nodes);


    /**
     * @param teachplanDTO 源对象
     * @return 转换后的对象
     * @Mapping 映射的是不能转换的属性
     */
    @Mapping(source = "teachPlanId", target = "id")
    Teachplan dto2entity(TeachplanDTO teachplanDTO);

    /**
     * @param vo 源对象
     * @return 转换后的对象
     */
    TeachplanDTO vo2dto(TeachplanVO vo);

    /**
     * @param teachplan 源对象
     * @return 转换后的对象
     */
    @Mapping(source = "id", target = "teachPlanId")
    TeachplanDTO entity2dto(Teachplan teachplan);

    /**
     * @param teachplanMedia 源对象
     * @return 转换后的对象
     */
    @Mapping(source = "id", target = "teachplanMediaId")
    TeachplanMediaDTO entity2dto(TeachplanMedia teachplanMedia);

}
